<!DOCTYPE html>
<html>
<head th:replace="admin/common/html/head :: head(~{::title},~{::link},~{::style})">
<title>项目首页</title>

<!-- 这儿引用单独的css link -->
<!-- Ladda for Bootstrap 3按钮加载进度插件 -->
<link rel="stylesheet">
<style type="text/css">
/**
*这里写单独的css样式
*/
</style>
</head>
<body>


<div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
    <button  type="button" class="btn btn-primary">
         <span class="entypo-plus-squared"></span><a style="color: white;" th:href="@{/admin/index}">返回</a>
     </button>
</div>
<table id="dataTable" class="table-striped footable-res footable metro-blue" data-page-size="6">
</table>



<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js">
</div>
<script type="text/javascript" th:inline="javascript">
var dataUrl=window.rootPath+"/TomcatController/list";
var startUrl=window.rootPath+"/TomcatController/startProject";
var stopUrl=window.rootPath+"/TomcatController/stopProject";
var cancelUrl=window.rootPath+"/TomcatController/undeployWebApp";
  var options = {
		dataUrl: dataUrl,
        sortName: "roleSort",
        modalName: "项目",
        search: false,
	    dataColumns: [
			{
			    checkbox: true
			}, 
			{
			    field: 'name',
			    title: '项目名'
			},
			{
			    field: 'ip',
			    title: 'IP'
			},
			{
			    field: 'port',
			    title: '端口'
			},
			{
			    field: 'status',
			    title: '状态'
			},
			{
			    field: 'url',
			    title: '路径',
			    formatter: function (value, row, index) {
			        var url ="http://"+row.ip+":"+row.port+"/"+row.name;
			        var actions = [];
			        actions.push('<a class="btn btn-info btn-xs" target="_blank"  href="'+url+'"><i class="fa fa-edit"></i>查看</a> ');
			        return actions.join('');
			    }
			},
			{
			    field: 'tomcatName',
			    title: '所属tomcat'
			},

			{
			    title: '操作',
			    formatter: function (value, row, index) {
			        var id = row.id;
			        var actions = [];
			        if(row.status == "运行"){
                        actions.push('<a class="btn btn-success btn-xs"  href="#" onclick="stop(\'' + row.name + '\',\'' + row.tomcatName + '\')"><i class="fa fa-edit"></i>停止</a> ');
                    } else {
                        actions.push('<a class="btn btn-success btn-xs"  href="#" onclick="run(\'' + row.name + '\',\'' + row.tomcatName + '\')"><i class="fa fa-edit"></i>启动</a> ');
                    }
			        actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="cancel(\'' + row.name + '\',\'' + row.tomcatName + '\')"><i class="fa fa-remove"></i>取消部署</a> ');
			        actions.push(' <a class="btn btn-warning btn-xs" href="javascript:putView(\''+row.tomcatName+'\',\''+row.name+'\')"><i class="fa fa-remove"></i>单文件更新</a> ');
			        return actions.join('');
			    }
			}]
  };
$(function(){
	var oTab=$.table.oTableInit(options);
	oTab.Init();
})



/* 启动*/
function run(projectName,tomcatName) {
	$.modal.confirm("确认要启动选中项目吗？", function() {
	    $.ajax({
            url: startUrl+"/"+projectName+"/"+tomcatName,
            type: "PUT",
            success:function(result){
                alert(result.msg);
                if(result.code == 200){
                    location.reload()
                }
            }
        });
    })
}

function stop(projectName,tomcatName) {
    $.modal.confirm("确认要停止选中项目吗？", function() {
        $.ajax({
            url: stopUrl+"/"+projectName+"/"+tomcatName,
            type: "PUT",
            success:function(result){
                alert(result.msg);
                if(result.code == 200){
                    location.reload()
                }
            }
        });
    })
}
function cancel(projectName,tomcatName) {
    $.modal.confirm("确认取消部署选中项目吗？", function() {
        $.ajax({
            url: cancelUrl+"/"+projectName+"/"+tomcatName,
            type: "PUT",
            success:function(result){
                alert(result.msg);
                if(result.code == 200){
                    location.reload()
                }
            }
        });
    })
}

function putView(tomcatName,projectUrl){
	localStorage.setItem("tomcatName",tomcatName);
	localStorage.setItem("projectUrl",projectUrl);
	window.location.href="putView"
	
	
}
</script>


</body>
</html>